class Restaurants::SessionsController < ApplicationController
  layout 'restaurant_session'

    def new
        if session[:restaurant_id].present?
            redirect_to "/restaurants/welcome"
        end    
    end   

    def create
        login = params[:login]
        password = params[:password]
        restaurant = Restaurant.authentication(login,password)
        if restaurant
            session[:restaurant_id] = restaurant.id
            flash[:notice] = nil
            redirect_to "/restaurants/welcome"
        else
            flash[:notice] = '用户名或密码错误'
            render :new    
        end    
    end  

    def logout
        if session[:restaurant_id].present?
            session[:restaurant_id] = nil
        end    
        redirect_to "/restaurants"
    end    
end
